package com.lilong.jwt.entity.user;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.lilong.jwt.common.base.BaseEntity;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;

@Entity
@Getter
@Setter
@Table(name = "tu_role")
public class Role extends BaseEntity {
    /**
     * 角色名称
     */
    @NotNull(message = "名称"+NOT_NULL)
    private String name;
    /**
     * 描述
     */
    @NotNull(message = "描述"+NOT_NULL)
    private String description;
    /**
     * 备注
     */
    private String remark;

    @ManyToMany(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
    @JoinTable(
            name = "tu_role_permissions",
            joinColumns = @JoinColumn(
                    name = "role_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(
                    name = "permissions_id", referencedColumnName = "id"))
    @JsonIgnoreProperties("roles")
    private List<Permission> permissions;
}
